﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace System.IO
{
    public static class IOExtensions
    {
        public static string FullNameWithoutExtension(this FileInfo file)
        {
            int length = file.FullName.LastIndexOf('.');
            if (length == -1)
            {
                return file.FullName;
            }
            return file.FullName.Substring(0, length);

        }

        public static string NameWithoutExtension(this FileInfo file)
        {
            return Path.GetFileNameWithoutExtension(file.Name);
        }

        public static string Combine(params string[] paths)
        {
            if (paths.Length == 0)
            {
                return string.Empty;
            }

            string path = paths[0];

            for (int i = 1; i < paths.Length; i++)
            {
                path = Path.Combine(path, paths[i]);
            }


            return path;
        }
    }
}

namespace System.Collections.Generic
{
    public static class CollectionsExtensions
    {
        public static string ToStringAll<T>(this List<T> list)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in list)
            {
                sb.Append(item.ToString());
                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }

        public static List<int> FindAllIndex<T>(this List<T> container, Predicate<T> match)
        {
            var items = container.FindAll(match);
            List<int> indexes = new List<int>();
            foreach (var item in items)
            {
                indexes.Add(container.IndexOf(item));
            }

            return indexes;
        }
    }
}

namespace System.Drawing
{
    public static class DrawingExtensions
    {
        public static string ImageType(this Image image)
        {
            if (image.RawFormat.Equals(ImageFormat.Bmp))
            {
                return "Bmp";
            }
            else if (image.RawFormat.Equals(ImageFormat.MemoryBmp))
            {
                return "BMP";
            }
            else if (image.RawFormat.Equals(ImageFormat.Wmf))
            {
                return "Emf";
            }
            else if (image.RawFormat.Equals(ImageFormat.Wmf))
            {
                return "Wmf";
            }
            else if (image.RawFormat.Equals(ImageFormat.Gif))
            {
                return "Gif";
            }
            else if (image.RawFormat.Equals(ImageFormat.Jpeg))
            {
                return "Jpeg";
            }
            else if (image.RawFormat.Equals(ImageFormat.Png))
            {
                return "Png";
            }
            else if (image.RawFormat.Equals(ImageFormat.Tiff))
            {
                return "Tiff";
            }
            else if (image.RawFormat.Equals(ImageFormat.Exif))
            {
                return "Exif";
            }
            else if (image.RawFormat.Equals(ImageFormat.Icon))
            {
                return "Ico";
            }

            return "";
        }
    }
}
